use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(ProjectInfo::Table)
                    .if_not_exists()
                    .col(pk_auto(ProjectInfo::Id))
                    .col(integer(ProjectInfo::GitlabInfoId))
                    .col(big_integer(ProjectInfo::ProjectId))
                    .col(string(ProjectInfo::ProjectName))
                    .col(string_null(ProjectInfo::WebUrl))
                    .col(date_time_null(ProjectInfo::CreateTime))
                    .to_owned(),
            )
            .await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .drop_table(Table::drop().table(ProjectInfo::Table).to_owned())
            .await
    }
}

#[derive(DeriveIden)]
enum ProjectInfo {
    Table,
    Id,
    GitlabInfoId,
    ProjectId,
    ProjectName,
    WebUrl,
    CreateTime,
}
